package com.obligatorio.domain.utils;

import java.util.Properties;
import javax.mail.Message;
import javax.mail.Session;
import javax.mail.Transport;
import javax.mail.internet.InternetAddress;
import javax.mail.internet.MimeMessage;

//copy this try block in the doPost method:
public class SendMail {
	
	
	public static void main(String[] args) {
		try {

			
			int a = 4;
			
			
			System.out.println(a);
			String from = "ObliLinked@gmail.com";
			String password = "Falta*Definir";
			Properties props = new Properties();
			props.put("mail.smtp.host", "smtp.gmail.com");
			props.put("mail.smtp.auth", "true");
			props.put("mail.smtp.port", "587");
			props.put("mail.smtp.socketFactory.port", "587");
			props.put("mail.smtp.starttls.enable", "true");

			Session s = Session.getInstance(props, null);
			s.setDebug(true);

			MimeMessage msg = new MimeMessage(s);
			String fromEmail = "ObliLinked@gmail.com";
			String addressTo = "nborde@gmail.com";
			InternetAddress to = new InternetAddress(addressTo);

			InternetAddress fromAddr = new InternetAddress(fromEmail);

			msg.setSentDate(new java.util.Date());
			msg.setFrom(fromAddr);
			msg.addRecipient(Message.RecipientType.TO, to);

			msg.setSubject("hi");
			msg.setContent("hello", "text/plain& quot;");
			// TODO: try it for text/html.

			Transport tr = s.getTransport("smtp");
			String smtp_server = props.getProperty("mail.smtp.host");

			tr.connect(smtp_server, from, password);
			msg.saveChanges();
			tr.sendMessage(msg, msg.getAllRecipients());
			tr.close();

		} catch (Exception e) {
			e.printStackTrace();
			// ignore
		}
	}
}
